package com.seven.domain;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.Data;

import java.util.List;

/**
 * @author seven
 * @date 2020/10/18 15:44
 */

@Data
public class Response<T> {

    private int code;

    private String msg;

    private Long count;

    private List<T> data;

    public static <T> Response<T> success(IPage<T> data) {
        Response<T> response = new Response<>();
        response.setData(data.getRecords());
        response.setCount(data.getTotal());
        response.setCode(0);
        response.setMsg("OK");
        return response;
    }

    public static <T> Response<T> successList(List<T> data) {
        Response<T> response = new Response<>();
        response.setData(data);
        response.setCode(0);
        response.setMsg("OK");
        return response;
    }

    public static <T> Response<T> successMsg(String msg) {
        Response<T> response = new Response<>();
        response.setMsg(msg);
        response.setCode(0);
        return response;
    }

    public static <T> Response<T> success() {
        Response<T> response = new Response<>();
        response.setCode(0);
        response.setMsg("OK");
        return response;
    }


    public static <T> Response<T> fail(String message) {
        Response<T> response = new Response<>();
        response.setMsg(message);
        response.setCode(1);
        return response;
    }

}
